package cn.edu.java.grammar;

public class Synchronized {
    public synchronized void func1() {
        System.out.println("func1!");
        try {
            Thread.sleep(5000);
            System.out.println("sleep time over!");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public synchronized void func2() {
        System.out.println("func2!");
    }

    public static void main(String[] args) {
        Synchronized aSynchronized = new Synchronized();

        Thread t1 = new Thread(aSynchronized::func1);

        Thread t2 = new Thread(aSynchronized::func2);

        t1.start();
        t2.start();
    }
}
